package com.mystudy.concurrent.designModel.futureModel;

import java.util.function.Consumer;

/**
 * TODO: 对{@link MyFuture}跟{@link MyFutureTask}进行了桥接
 *
 * @author acy
 * @since 2019/05/29 17:05
 */
public class MyFutureService {
	public <T> MyFuture<T> submit(final MyFutureTask<T> task, final Consumer<T> consumer) {
		MyAsynFutrue<T> asynFutrue = new MyAsynFutrue<>();
		new Thread(() -> {
			T result = task.call();
			asynFutrue.done(result);
			consumer.accept(result);
		}).start();
		return asynFutrue;
	}
}
